﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Web;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Filters;
using EPiServer.ServiceLocation;

namespace EPiBoost.Core.DataAnnotations
{
	public class AutoImageUrlAttribute : EPiServer.DataAnnotations.ImageUrlAttribute
	{
		public AutoImageUrlAttribute(Type type)
			: base(GetUrl(type))
		{ 
			
		}

		private static string GetUrl(Type type)
		{
			if (Configuration.Core.Handlers.PageTypeThumbnailHandler.Enabled)
			{
				var url = string.Format("~/_Episerver/ContentTypeImages/{0}.jpg", type.FullName);
				if (HttpContext.Current != null)
				{
					return System.Web.VirtualPathUtility.ToAbsolute(url); 
				}
			}
			return "404.jpg";
		}


	}
}
